<template>
	<div>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-icon mui-icon-left-nav" @click="goBack"></a>
			<h1 class="mui-title">{{title}}</h1>
		</header>
		<div id="myList" class="mui-content otherContent">
			<div class="mui-input-row mui-search mySearch">
				<input class="search mui-input-clear" type="search" ng-model="words" placeholder="搜索" ng-focus="showSearch = true">
			</div>
			<div v-show="!showSearch" class="container">
				<scroller :on-infinite="infinite" ref="my_scroller">
					<ul class="mui-table-view ulList">
						<li class="mui-table-view-cell mui-media" v-for="list in dataList" @click="goDetailList(list.InstanceId,list.Bookmark,list.State,list.UpdateDate)">
							<a taptohref>
								<span class="radius">{{list.CreateUserName}}</span>
								<div class="mui-media-body item-desc">
									{{list.CreateUserName}}的{{list.WorkflowName}}
									<p class="mui-ellipsis">{{getStatus(list.State)}}</p>
									<span class="showTime">{{getDate(list.CreateDate)}}</span>
								</div>
							</a>
						</li>
					</ul>
					<div style="height: 1px;"></div>
				</scroller>
			</div>
			<!--<div v-show="!showSearch" class="mui-scroll-wrapper" id="refreshContainer" refresh style="overflow: scroll;">
				<div class="scroll">
					<ul class="mui-table-view ulList">
						<li class="mui-table-view-cell mui-media" v-for="list in dataList" @click="goDetailList(list.InstanceId,list.Bookmark,list.State,list.UpdateDate)">
							<a taptohref>
								<span class="radius">{{list.CreateUserName}}</span>
								<div class="mui-media-body item-desc">
									{{list.CreateUserName}}的{{list.WorkflowName}}
									<p class="mui-ellipsis">{{getStatus(list.State)}}</p>
									<span class="showTime">{{getDate(list.CreateDate)}}</span>
								</div>
							</a>
						</li>
					</ul>
				</div>
			</div>-->
			<div v-show="showSearch" class="history" searchHistory>
				<div class="hasContent">
					<p>搜索历史</p>
					<ul class="serachList">
						<li ng-click="searchCode(item.SearchContent)" ng-repeat="item in searchList">
							<a>item.SearchContent</a>
						</li>
					</ul>
					<a class="clear" href="" ng-click="clearHistory()">清空历史记录</a>
					<a class="clear" href="" ng-click="showSearch = false">返回</a>
				</div>
				<!--<div class="noContent" ng-if="!showContent">-->
				<!--<div>-->
				<!--<img src="./static/images/search_2.png"/>-->
				<!--<p>未搜索到“<span>111</span>”相关结果</p>-->
				<!--</div>-->
				<!--</div>-->
			</div>
		</div>
	</div>
</template>
<script>
	import {
		myList,
		waitList,
		overList,
		getCurrNode
	} from '@/service/getData';
	import {
		loadFromLocal
	} from '@/service/store';
	export default {
		data() {
				return {
					title: "",
					showSearch: false,
					state: null,
					myUser: loadFromLocal("myUser", "obj"),
					dataList: [],
					hasBack: 0,
					page: 0,
					init: false
				}
			},
			created() {
				this.state = this.$route.params.state;
				let self = this;
				switch(this.state) {
					case '0':
						{
							self.title = "待我审批";
							waitList({
								userId: self.myUser.userId,
								schoolId: self.myUser.schoolId,
								PageIndex: this.page++,
								PageSize: 10
							}).then((res) => {
								self.init = true;
								self.dataList = res.data;
								self.$refs.my_scroller.finishInfinite(false)
							});
						}
						break;
					case '1':
						{
							self.title = "我发起的";
							myList({
								userId: self.myUser.userId,
								schoolId: self.myUser.schoolId,
								PageIndex: this.page++,
								PageSize: 10
							}).then((res) => {
								self.init = true;
								self.dataList = res.data;
								self.$refs.my_scroller.finishInfinite(false)
							});
						}
						break
					case '2':
						{
							self.title = "我审核的";
							overList({
								userId: self.myUser.userId,
								schoolId: self.myUser.schoolId,
								PageIndex: this.page++,
								PageSize: 10
							}).then((res) => {
								self.init = true;
								self.dataList = res.data;
								self.$refs.my_scroller.finishInfinite(false)
							});
						}
						break;
					default:
						break;
				}
			},
			methods: {
				infinite(done) {
					if(!this.init) {
						return false;
					}
					let self = this;
					//数据不满一屏，自动补满
					setTimeout(() => {
						switch(this.state) {
							case '0':
								{
									self.title = "待我审批";
									waitList({
										userId: self.myUser.userId,
										schoolId: self.myUser.schoolId,
										PageIndex: this.page++,
										PageSize: 10
									}).then((res) => {
										if(res.data != null) {
											if(res.data.length == 10) {
												setTimeout(() => {
													done()
												})
											} else {
												setTimeout(() => {
													self.$refs.my_scroller.finishInfinite(false)
												});
											}
											self.dataList = self.dataList.concat(res.data);
										} else {
											done(true)
										}
									});
								}
								break;
							case '1':
								{
									self.title = "我发起的";
									myList({
										userId: self.myUser.userId,
										schoolId: self.myUser.schoolId,
										PageIndex: this.page++,
										PageSize: 10
									}).then((res) => {
										if(res.data != null) {
											if(res.data.length == 10) {
												setTimeout(() => {
													done()
												})
											} else {
												setTimeout(() => {
													self.$refs.my_scroller.finishInfinite(false)
												});
											}
											self.dataList = self.dataList.concat(res.data);
										} else {
											done(true)
										}
									});
								}
								break
							case '2':
								{
									self.title = "我审核的";
									overList({
										userId: self.myUser.userId,
										schoolId: self.myUser.schoolId,
										PageIndex: this.page++,
										PageSize: 10
									}).then((res) => {
										if(res.data != null) {
											if(res.data.length == 10) {
												setTimeout(() => {
													done()
												})
											} else {
												setTimeout(() => {
													self.$refs.my_scroller.finishInfinite(false)
												});
											}
											self.dataList = self.dataList.concat(res.data);
										} else {
											done(true)
										}
									});
								}
								break;
							default:
								break;
						}

					}, 500)
				},
				//转换当前节点状态
				getStatus(state) {
					switch(state) {
						case 0:
							return "审批中";
						case 1:
							return "完成";
						case 2:
							return "已撤销";
							//						case 3:
							//							return "已退回";
						default:
							return "审批中";
					}
				},
				//获取日期
				getDate(date) {
					return new Date(date).Format("yyyy-MM-dd hh:mm")
				},
				//查看详情
				goDetailList(instanceId, bookmark, state, updateDate) {
					let self = this;
					//					if(state == 2) {
					//						alert('重新发起页面')
					//						getCurrNode({
					//							InstanceId: instanceId
					//						}).then((res) => {
					//							let url = res.data.formUrlMobile;
					//							debugger
					//							self.$router.push({
					//								name: url,
					//								params: {
					//									workflowId: "null",
					//									instanceId: instanceId
					//								}
					//							})
					//						});
					//					} else {
					if((state != 0 && state != 2) || updateDate) {
						this.hasBack = 1 //hasBack=0时可撤销 为1不可撤销
							//			            window.Pantosoft.IT.Utility.msg("只能撤销未经审批的流程！");
							//			            return false;
					}

					//获取当前流程类型
					getCurrNode({
						InstanceId: instanceId
					}).then((res) => {
						let url = res.data.formUrlMobile.indexOf('Detail') != -1 ? res.data.formUrlMobile : 'Detail' + res.data.formUrlMobile;
						//							leave   DetailLeave
//						debugger
						self.$router.push({
							name: url,
							params: {
								instanceId: instanceId,
								bookmark: bookmark,
								state: self.state,
								status: state,
								hasBack: self.hasBack
							}
						})
					});
					//					}

				},

			}
	}
</script>
<style>

</style>